<template>
	<view class="content">
		<view class="block user-block"
			:style="'height:'+(custom.navHeight)+'rpx;width:calc(100% - '+(custom.navWidth+custom.navMarRight)+'rpx);margin-top:'+(custom.statusBar+custom.nvaMartom)+'rpx'">
			<view @click="backup" class="iconfont icon-zuojiantou backup-btn"></view>
			<view class="user">
				<image :src="cus.faceUrl" :style="'width:'+(custom.navHeight)+'rpx;height:'+(custom.navHeight)+'rpx'"
					class="user-photo">
				</image>
				<view class="user-name">{{cus.notName}}</view>
			</view>
			<view class="attention">关注</view>
		</view>
		<view
			:style="'overflow-y: scroll;height:calc(100vh - 120rpx - '+(custom.navHeight)+'rpx - '+(custom.statusBar+custom.nvaMartom)+'rpx - 30rpx);'">
			<view class="detail-block">
				<view class="swiper-block">
					<swiper style="width: 100%;height: 540rpx;" autoplay="true" indicator-dots="true"
						indicator-color="#999" indicator-active-color="#fff">
						<swiper-item style="width: 100%;height: 540rpx;" :item-id="item.id"
							v-for="(item,index) in swiperList" :key="item.id">
							<image mode="aspectFill" style="width: 100%;height: 540rpx;" :src="item.imgUrl"></image>
						</swiper-item>
					</swiper>
				</view>
				<view class="detail-content">
					<mp-html :content="content"></mp-html>
				</view>
				<view class="time">{{crtTime}}</view>
			</view>
			<view class="comments-list">
				<view class="total">共 {{count}} 条评论</view>
				<view class="comments-content">
					<view v-for="(item,index) in comments" :key="item.id" class="comments-item">
						<image :src="item.faceUrl" mode="aspectFill" class="user-photo"></image>
						<view class="info-block">
							<view class="user-name">{{item.notName}}</view>
							<view class="comments-detail">{{item.comContent}}</view>
							<view class="time">{{item.crtTime}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="comments-block">
			<view class="input-block">
				<view class="iconfont icon-bianji"></view>
				<input @blur="getInput" placeholder-class="inputPlaceholder" placeholder="说点什么……" v-model="comContent">
			</view>
			<view class="operation">
				<view class="operation-item" v-if="isFabulous==1" @click="delList(1)">
					<view class="iconfont icon-zanxuanzhong"></view>
					<view class="num">{{fabulous}}</view>
				</view>
				<view class="operation-item" v-if="isFabulous!=1" @click="addList(1)">
					<view class="iconfont icon-zan"></view>
					<view class="num">{{fabulous}}</view>
				</view>
				<view class="operation-item" v-if="isCollect==1" @click="delList(2)">
					<view class="iconfont icon-shoucangfill"></view>
					<view class="num">{{collect}}</view>
				</view>
				<view class="operation-item" v-if="isCollect!=1" @click="addList(2)">
					<view class="iconfont icon-shoucang1"></view>
					<view class="num">{{collect}}</view>
				</view>
				<view class="operation-item">
					<view class="iconfont icon-pinglun"></view>
					<view class="num">{{discuss}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		postAddInteract,
		getSpecialtyDetail,
		getFindInteractBy,
		postDelInteract
	} from '@/api/vlog.js';
	export default {
		data() {
			return {
				count: 0,
				fabulous: 0,
				collect: 0,
				discuss: 0,
				isFabulous: 0,
				isCollect: 0,
				cus: [],
				custom: null,
				crtTime: '',
				comContent: '',
				swiperList: [

				],
				content: '',
				comments: [],

			}
		},
		methods: {
			backup() {
				uni.navigateBack();
			},
			getInput(e) {
				uni.$emit('getInput', e.detail.value);
				this.addList(3)
			},
			getList() {
				getSpecialtyDetail({
					id: this.id
				}).then((res) => {
					if (res.code == 1) {
						if (res.data != null) {
							this.swiperList = res.data.imgList
							this.content = res.data.content
							this.crtTime = res.data.crtTime
							this.cus = res.data.customer
							this.fabulous = res.data.fabulous
							this.collect = res.data.collect
							this.discuss = res.data.discuss
							this.isFabulous = res.data.isFabulous
							this.fabulous = res.data.fabulous
							this.isCollect = res.data.isCollect
							console.log(res)
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//查询评论
			getInteractList() {
				console.log(this.id)
				getFindInteractBy({
					cid: this.id,
					cType: 3
				}).then((res) => {
					if (res.code == 1) {
						this.comments = res.data;
						this.count = res.count;


					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},

			//新增评论
			addList(e) {
				if (e != 3) {
					this.comContent = '';
				}
				postAddInteract({
					id: 0,
					cid: this.id,
					cType: e,
					comContent: this.comContent
				}).then((res) => {
					if (res.code == 1) {
						if (e == 3) {
							uni.showToast({
								title: '评论成功',
								mask: true,
							})
							this.getInteractList();
						}
						if (e == 1) {
							this.isFabulous = 1
							this.fabulous = this.fabulous + 1
						}
						if (e == 2) {
							this.isCollect = 1
							this.collect = this.collect + 1
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			delList(e) {
				if (e != 3) {
					this.comContent = '';
				}
				postDelInteract({
					id: 0,
					cid: this.id,
					cType: e,
					comContent: this.comContent
				}).then((res) => {
					if (res.code == 1) {
						if (e == 3) {
							uni.showToast({
								title: '删除成功',
								mask: true,
							})
						}
						if (e == 1) {
							this.isFabulous = 0
							this.fabulous = this.fabulous - 1
						}
						if (e == 2) {
							this.isCollect = 0
							this.collect = this.collect - 1
						}
						this.getInteractList()
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			}
		},
		mounted() {
			/*自适应微信胶囊按钮*/
			this.custom = this.utils.getCustomNavData();
		},
		onLoad(e) {
			console.log(e.id)
			this.id = e.id;
			this.getInteractList()
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;

		.user-block {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;
			padding-right: 20rpx;

			.iconfont.backup-btn {
				display: flex;
				align-items: center;
				flex-grow: 0;
				margin-left: 20rpx;
				color: $color-secondary-text;
				font-size: 36rpx;
			}

			.user {
				flex-grow: 1;
				display: flex;
				flex-direction: row;
				align-items: center;

				.user-photo {
					border-radius: 50%;
					margin: 0 16rpx;
				}

				.user-name {
					display: flex;
					align-items: center;
					font-size: 30rpx;
					font-weight: bold;
				}
			}

			.attention {
				background: #fff;
				border: 1px solid $color-primary;
				color: $color-primary;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				height: 80%;
				width: 120rpx;
				font-size: 30rpx;
				font-weight: bold;
			}
		}

		.detail-block {
			display: flex;
			flex-direction: column;

			.swiper-block {
				width: 100%;
			}

			.detail-content {
				width: 100%;
				padding: 30rpx;
				line-height: 2;
			}
		}

		.time {
			padding: 0 30rpx;
			color: $color-secondary-text;
			font-size: 24rpx;
		}

		.comments-list {
			display: flex;
			flex-direction: column;
			padding: 30rpx;

			.total {
				padding-top: 30rpx;
				border-top: 1px solid #efefef;
				font-size: 28rpx;
				color: $color-regular-text;
				margin-bottom: 20rpx;
			}

			.comments-content {
				display: flex;
				flex-direction: column;

				.comments-item {
					display: flex;
					flex-direction: row;
					border-bottom: 1px solid #efefef;
					padding: 30rpx 0;

					.user-photo {
						width: 70rpx;
						height: 70rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}

					.info-block {
						width: calc(100% - 90rpx);
						display: flex;
						flex-direction: column;

						.user-name {
							color: $color-regular-text;
							font-size: 28rpx;
						}

						.comments-detail {
							font-size: 28rpx;
							margin: 16rpx 0;
						}

						.time {
							font-size: 24rpx;
							color: $color-regular-text;
							padding: 0;
						}
					}
				}

				.comments-item:last-child {
					border: none;
				}
			}
		}

		.comments-block {
			border-top: 1px solid #efefef;
			position: fixed;
			padding: 0 20rpx;
			bottom: 0;
			left: 0;
			height: 120rpx;
			width: 100%;
			background: #fff;
			display: flex;
			flex-direction: row;
			align-items: center;

			.input-block {
				width: 280rpx;
				height: 70rpx;
				background: #F3F3F3;
				border-radius: 40rpx;
				flex-grow: 0;
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 0 20rpx;

				input {
					font-size: 28rpx;
				}

				.iconfont {
					margin-right: 10rpx;
				}
			}

			.operation {
				display: flex;
				flex-direction: row;
				align-items: center;
				flex-grow: 1;
				height: 70rpx;

				.operation-item {
					height: 100%;
					width: calc(100%/3);
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: center;

					.num {
						font-size: 30rpx;
					}

					.iconfont {
						margin-right: 10rpx;
						font-size: 52rpx;
					}

					.icon-zanxuanzhong {
						color: #E6404A;
					}

					.icon-shoucangfill {
						color: #F2BE68;
					}

				}
			}
		}
	}
</style>
